package com.wisdom.benefit.jufa.base;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * Created on 2018/12/26 11:12.
 *
 * @author zhoudawei
 */
public abstract class BaseLazyLoadFragment extends BaseFragment {

    protected boolean isFirst = true;
    protected boolean isViewCreated;

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        isViewCreated = true;
        if (getUserVisibleHint())
            lazyLoad();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        isViewCreated = false;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser && isViewCreated) {
            lazyLoad();
        }
    }

    abstract protected void lazyLoad();
}
